package com.orange.wwwapi.controller.sms;

import com.orange.core.pojo.BR;
import com.orange.core.pojo.R;
import com.orange.core.pojo.enums.EErrorCode;
import com.orange.wwwapi.pojo.req.sms.SendVerifyCodeReq;
import com.orange.wwwapi.service.sms.SmsService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 短信
 */
@Slf4j
@RequiredArgsConstructor
@RestController
@RequestMapping("/sms")
public class SmsController {

    private final SmsService smsService;

    /**
     * 发送验证码
     *
     * @param sendVerifyCodeReq 区号，手机号
     * @return 成功/失败
     */
    @PostMapping("/sendVerifyCode")
    public R<Boolean> sendVerifyCode(@RequestBody SendVerifyCodeReq sendVerifyCodeReq) {
        try {
            return BR.result(smsService.sendVerifyCode(sendVerifyCodeReq));
        } catch (Exception e) {
            log.error("短信发送失败：", e);
            return R.fail(EErrorCode.PARAM_ERROR, "短信发送失败");
        }
    }
}
